#pragma once

#include <iostream>
#include <pthread.h>


//将锁进行封装
//自己不维护锁，外部传入


class Mutex
{
public:
    Mutex(pthread_mutex_t* pmutex)
    :_pmutex(pmutex)
    {}
    ~Mutex()
    {}
    void lock()
    {
        pthread_mutex_lock(_pmutex);
    }
    void unlock()
    {
        pthread_mutex_unlock(_pmutex);
    }

private:
    pthread_mutex_t* _pmutex;
};


class LockGuard
{
public:
    LockGuard(pthread_mutex_t* pmutex)
    :_mutex(pmutex)
    {
        _mutex.lock();
    }
    ~LockGuard()
    {
        _mutex.unlock();
    }
private:
    Mutex _mutex;
};